<template>
  <div class="biweekly-report-container">
    <el-card class="report-card" shadow="hover">
      <div class="header">
        <div class="title-section">
          <h2 class="page-title">
            <el-icon class="title-icon"><Document /></el-icon>
            双周报报表
            <el-tag v-if="projectData.project_name" type="primary" size="small" style="margin-left: 10px;">
              {{ projectData.project_name }}
            </el-tag>
          </h2>
          <p class="description">
            根据项目信息生成双周报报表，支持导出为Excel或PDF格式
            <span v-if="projectData.project_id" style="color: #e6a23c; font-weight: 500;">
              (项目编号: {{ projectData.project_id }})
            </span>
          </p>
        </div>
        <div class="action-buttons">
          <el-button type="primary" @click="generateReport" :loading="generating">
            <el-icon><Refresh /></el-icon>
            生成报表
          </el-button>
          <el-button type="success" @click="exportToExcel" :disabled="!reportData" :loading="exporting">
            <el-icon><Download /></el-icon>
            导出Excel
          </el-button>
          <el-button type="warning" @click="exportToPDF" :disabled="!reportData" :loading="exporting">
            <el-icon><Document /></el-icon>
            导出PDF
          </el-button>
        </div>
      </div>

      <!-- 报表配置区域 -->
      <div class="config-section">
        <el-form :model="reportConfig" label-width="120px" inline>
          <el-form-item label="报表周期">
            <el-date-picker
              v-model="reportConfig.startDate"
              type="date"
              placeholder="开始日期"
              format="YYYY-MM-DD"
              value-format="YYYY-MM-DD"
              style="width: 150px;"
            />
            <span style="margin: 0 10px;">至</span>
            <el-date-picker
              v-model="reportConfig.endDate"
              type="date"
              placeholder="结束日期"
              format="YYYY-MM-DD"
              value-format="YYYY-MM-DD"
              style="width: 150px;"
            />
          </el-form-item>
          <el-form-item label="报表类型">
            <el-select v-model="reportConfig.type" placeholder="选择报表类型" style="width: 150px;">
              <el-option label="项目进度报表" value="progress" />
              <el-option label="问题汇总报表" value="issues" />
              <el-option label="资源使用报表" value="resources" />
              <el-option label="综合报表" value="comprehensive" />
            </el-select>
          </el-form-item>
        </el-form>
      </div>

      <!-- 加载状态 -->
      <div v-if="loading" class="loading-section">
        <el-skeleton :rows="10" animated />
      </div>

      <!-- 报表内容 -->
      <div v-else-if="reportData" class="report-content">
        <!-- 报表头部 -->
        <div class="report-header">
          <h1 class="report-title">双周报报表</h1>
          <div class="report-info">
            <p><strong>项目名称：</strong>{{ projectData?.project_name }}</p>
            <p><strong>报表周期：</strong>{{ reportConfig.startDate }} 至 {{ reportConfig.endDate }}</p>
            <p><strong>生成时间：</strong>{{ new Date().toLocaleString('zh-CN') }}</p>
          </div>
        </div>

        <!-- 项目基本信息 -->
        <div class="section">
          <h3 class="section-title">项目基本信息</h3>
          <el-descriptions :column="2" border>
            <el-descriptions-item label="项目编号">{{ projectData?.project_id }}</el-descriptions-item>
            <el-descriptions-item label="项目名称">{{ projectData?.project_name }}</el-descriptions-item>
            <el-descriptions-item label="项目地点">{{ projectData?.project_location }}</el-descriptions-item>
            <el-descriptions-item label="项目经理">{{ getUserNameById(projectData?.project_manager) }}</el-descriptions-item>
            <el-descriptions-item label="项目状态">
              <el-tag :type="getStateTagType(projectData?.state)" size="small">
                {{ projectData?.state }}
              </el-tag>
            </el-descriptions-item>
            <el-descriptions-item label="创建时间">{{ formatDate(projectData?.create_time) }}</el-descriptions-item>
            <el-descriptions-item label="总工时">{{ reportData.progress.totalHours || 0 }} 小时</el-descriptions-item>
            <el-descriptions-item label="预算总额">¥{{ reportData.resources?.budget?.total?.toLocaleString() || 0 }}</el-descriptions-item>
          </el-descriptions>
        </div>

        <!-- 数据概览 -->
        <div class="section">
          <h3 class="section-title">数据概览</h3>
          <el-row :gutter="20">
            <el-col :span="6">
              <el-card class="overview-card">
                <div class="overview-item">
                  <div class="overview-icon">
                    <el-icon><User /></el-icon>
                  </div>
                  <div class="overview-content">
                    <div class="overview-number">{{ reportData.stakeholders?.length || 0 }}</div>
                    <div class="overview-label">干系人</div>
                  </div>
                </div>
              </el-card>
            </el-col>
            <el-col :span="6">
              <el-card class="overview-card">
                <div class="overview-item">
                  <div class="overview-icon">
                    <el-icon><Document /></el-icon>
                  </div>
                  <div class="overview-content">
                    <div class="overview-number">{{ reportData.documents?.length || 0 }}</div>
                    <div class="overview-label">文档</div>
                  </div>
                </div>
              </el-card>
            </el-col>
            <el-col :span="6">
              <el-card class="overview-card">
                <div class="overview-item">
                  <div class="overview-icon">
                    <el-icon><DataBoard /></el-icon>
                  </div>
                  <div class="overview-content">
                    <div class="overview-number">{{ reportData.experiences?.length || 0 }}</div>
                    <div class="overview-label">经验总结</div>
                  </div>
                </div>
              </el-card>
            </el-col>
            <el-col :span="6">
              <el-card class="overview-card">
                <div class="overview-item">
                  <div class="overview-icon">
                    <el-icon><Refresh /></el-icon>
                  </div>
                  <div class="overview-content">
                    <div class="overview-number">{{ reportData.changes?.length || 0 }}</div>
                    <div class="overview-label">变更记录</div>
                  </div>
                </div>
              </el-card>
            </el-col>
          </el-row>
        </div>

        <!-- 进度汇总 -->
        <div class="section">
          <h3 class="section-title">进度汇总</h3>
          <el-row :gutter="20">
            <el-col :span="4">
              <el-card class="progress-card">
                <div class="progress-item">
                  <div class="progress-number">{{ reportData.progress.totalTasks || 0 }}</div>
                  <div class="progress-label">总任务数</div>
                </div>
              </el-card>
            </el-col>
            <el-col :span="4">
              <el-card class="progress-card">
                <div class="progress-item">
                  <div class="progress-number">{{ reportData.progress.completedTasks || 0 }}</div>
                  <div class="progress-label">已完成</div>
                </div>
              </el-card>
            </el-col>
            <el-col :span="4">
              <el-card class="progress-card">
                <div class="progress-item">
                  <div class="progress-number">{{ reportData.progress.inProgressTasks || 0 }}</div>
                  <div class="progress-label">进行中</div>
                </div>
              </el-card>
            </el-col>
            <el-col :span="4">
              <el-card class="progress-card">
                <div class="progress-item">
                  <div class="progress-number">{{ reportData.progress.weightCompletionRate || 0 }}%</div>
                  <div class="progress-label">权重完成率</div>
                </div>
              </el-card>
            </el-col>
            <el-col :span="4">
              <el-card class="progress-card">
                <div class="progress-item">
                  <div class="progress-number">{{ reportData.progress.taskCompletionRate || 0 }}%</div>
                  <div class="progress-label">任务完成率</div>
                </div>
              </el-card>
            </el-col>
            <el-col :span="4">
              <el-card class="progress-card">
                <div class="progress-item">
                  <div class="progress-number">{{ reportData.progress.totalWeight || 0 }}</div>
                  <div class="progress-label">总权重</div>
                </div>
              </el-card>
            </el-col>
            <el-col :span="4">
              <el-card class="progress-card">
                <div class="progress-item">
                  <div class="progress-number">{{ reportData.progress.completedWeight || 0 }}</div>
                  <div class="progress-label">已完成权重</div>
                </div>
              </el-card>
            </el-col>
            <el-col :span="4">
              <el-card class="progress-card">
                <div class="progress-item">
                  <div class="progress-number">{{ reportData.progress.usedHours || 0 }}</div>
                  <div class="progress-label">已用工时</div>
                </div>
              </el-card>
            </el-col>
            <el-col :span="4">
              <el-card class="progress-card">
                <div class="progress-item">
                  <div class="progress-number">{{ reportData.progress.remainingHours || 0 }}</div>
                  <div class="progress-label">剩余工时</div>
                </div>
              </el-card>
            </el-col>
          </el-row>
        </div>

        <!-- 问题汇总 -->
        <div class="section">
          <h3 class="section-title">问题汇总</h3>
          <el-table 
            :data="reportData.issues || []" 
            stripe 
            border 
            class="issue-table"
            :header-cell-style="{ 
              background: '#f5f7fa', 
              color: '#606266',
              fontSize: '14px',
              fontWeight: '500'
            }"
            :cell-style="{ fontSize: '13px' }"
          >
            <el-table-column prop="issue_type" label="问题类型" min-width="120" />
            <el-table-column prop="description" label="问题描述" min-width="200" />
            <el-table-column prop="severity" label="严重程度" min-width="100">
              <template #default="scope">
                <el-tag :type="getSeverityType(scope.row.severity)" size="small">
                  {{ scope.row.severity }}
                </el-tag>
              </template>
            </el-table-column>
            <el-table-column prop="status" label="状态" min-width="100">
              <template #default="scope">
                <el-tag :type="getIssueStatusType(scope.row.status)" size="small">
                  {{ scope.row.status }}
                </el-tag>
              </template>
            </el-table-column>
            <el-table-column prop="create_time" label="创建时间" min-width="150" />
          </el-table>
        </div>

        <!-- 里程碑进度 -->
        <div class="section">
          <h3 class="section-title">里程碑进度</h3>
          <el-timeline>
            <el-timeline-item
              v-for="milestone in reportData.milestones || []"
              :key="milestone.id"
              :timestamp="milestone.plan_date"
              :type="getMilestoneType(milestone.status)"
            >
              <h4>{{ milestone.milestone_name }}</h4>
              <p>{{ milestone.description }}</p>
              <el-tag :type="getMilestoneStatusType(milestone.status)" size="small">
                {{ milestone.status }}
              </el-tag>
            </el-timeline-item>
          </el-timeline>
        </div>

        <!-- 资源使用情况 -->
        <div class="section">
          <h3 class="section-title">资源使用情况</h3>
          <el-row :gutter="20">
            <el-col :span="12">
              <h4>人力资源</h4>
              <el-table 
                :data="reportData.resources?.human || []" 
                stripe 
                border 
                class="resource-table"
                :header-cell-style="{ 
                  background: '#f5f7fa', 
                  color: '#606266',
                  fontSize: '14px',
                  fontWeight: '500'
                }"
                :cell-style="{ fontSize: '13px' }"
              >
                <el-table-column prop="name" label="姓名" min-width="100" />
                <el-table-column prop="role" label="角色" min-width="100" />
                <el-table-column prop="hours" label="工时" min-width="80" />
                <el-table-column prop="utilization" label="利用率" min-width="100">
                  <template #default="scope">
                    <el-progress :percentage="scope.row.utilization" :stroke-width="8" />
                  </template>
                </el-table-column>
              </el-table>
            </el-col>
            <el-col :span="12">
              <h4>预算使用</h4>
              <div class="budget-info">
                <div class="budget-item">
                  <span class="budget-label">总预算：</span>
                  <span class="budget-value">¥{{ reportData.resources?.budget?.total?.toLocaleString() || 0 }}</span>
                </div>
                <div class="budget-item">
                  <span class="budget-label">已使用：</span>
                  <span class="budget-value">¥{{ reportData.resources?.budget?.used?.toLocaleString() || 0 }}</span>
                </div>
                <div class="budget-item">
                  <span class="budget-label">剩余：</span>
                  <span class="budget-value">¥{{ reportData.resources?.budget?.remaining?.toLocaleString() || 0 }}</span>
                </div>
                <div class="budget-item">
                  <span class="budget-label">使用率：</span>
                  <span class="budget-value">
                    <el-progress :percentage="reportData.resources?.budget?.usageRate || 0" :stroke-width="8" />
                  </span>
                </div>
              </div>
            </el-col>
          </el-row>
        </div>

        <!-- 干系人管理 -->
        <div class="section">
          <h3 class="section-title">干系人管理</h3>
          <el-table 
            :data="reportData.stakeholders || []" 
            stripe 
            border 
            class="stakeholder-table"
            :header-cell-style="{ 
              background: '#f5f7fa', 
              color: '#606266',
              fontSize: '14px',
              fontWeight: '500'
            }"
            :cell-style="{ fontSize: '13px' }"
          >
            <el-table-column prop="name" label="姓名" min-width="120" />
            <el-table-column prop="role" label="角色" min-width="120" />
            <el-table-column prop="contact" label="联系方式" min-width="150" />
            <el-table-column prop="influence" label="影响力" min-width="100">
              <template #default="scope">
                <el-tag :type="getInfluenceType(scope.row.influence)" size="small">
                  {{ scope.row.influence }}
                </el-tag>
              </template>
            </el-table-column>
          </el-table>
        </div>

        <!-- 项目进度 -->
        <div class="section">
          <h3 class="section-title">项目进度</h3>
          <el-table 
            :data="reportData.schedule || []" 
            stripe 
            border 
            class="progress-table"
            :header-cell-style="{ 
              background: '#f5f7fa', 
              color: '#606266',
              fontSize: '14px',
              fontWeight: '500'
            }"
            :cell-style="{ fontSize: '13px' }"
          >
            <el-table-column prop="phase_name" label="阶段名称" min-width="150" />
            <el-table-column prop="phase_code" label="阶段代码" min-width="100" />
            <el-table-column prop="weight" label="权重" min-width="80" />
            <el-table-column prop="completion_rate" label="完成率" min-width="100">
              <template #default="scope">
                <el-progress :percentage="scope.row.completion_rate || 0" :stroke-width="8" />
              </template>
            </el-table-column>
            <el-table-column prop="completed_weight" label="已完成权重" min-width="120" />
            <el-table-column prop="contribution" label="贡献度" min-width="100">
              <template #default="scope">
                <el-tag type="warning" size="small">{{ scope.row.contribution || 0 }}%</el-tag>
              </template>
            </el-table-column>
            <el-table-column prop="status" label="状态" min-width="100">
              <template #default="scope">
                <el-tag :type="getPhaseStatusType(scope.row.status)" size="small">
                  {{ scope.row.status }}
                </el-tag>
              </template>
            </el-table-column>
            <el-table-column prop="start_date" label="开始日期" min-width="120" />
            <el-table-column prop="end_date" label="结束日期" min-width="120" />
          </el-table>
        </div>

        <!-- 进度趋势分析 -->
        <div class="section">
          <h3 class="section-title">进度趋势分析</h3>
          <el-row :gutter="20">
            <el-col :span="12">
              <el-card class="trend-card">
                <template #header>
                  <div class="trend-header">
                    <span>权重完成情况</span>
                    <el-tag type="primary">{{ reportData.progress.completedWeight }}/{{ reportData.progress.totalWeight }}</el-tag>
                  </div>
                </template>
                <div class="trend-content">
                  <el-progress 
                    :percentage="reportData.progress.weightCompletionRate" 
                    :stroke-width="12"
                    :color="getProgressColor(reportData.progress.weightCompletionRate)"
                  />
                  <p class="trend-description">
                    项目权重完成率: {{ reportData.progress.weightCompletionRate }}%
                  </p>
                </div>
              </el-card>
            </el-col>
            <el-col :span="12">
              <el-card class="trend-card">
                <template #header>
                  <div class="trend-header">
                    <span>任务完成情况</span>
                    <el-tag type="success">{{ reportData.progress.completedTasks }}/{{ reportData.progress.totalTasks }}</el-tag>
                  </div>
                </template>
                                  <div class="trend-content">
                    <el-progress 
                      :percentage="reportData.progress.taskCompletionRate" 
                      :stroke-width="12"
                      color="#67c23a"
                    />
                    <p class="trend-description">
                     任务完成率: {{ reportData.progress.taskCompletionRate }}%
                    </p>
                  </div>
              </el-card>
            </el-col>
          </el-row>
        </div>

        <!-- 文档管理 -->
        <div class="section">
          <h3 class="section-title">文档管理</h3>
          <el-table 
            :data="reportData.documents || []" 
            stripe 
            border 
            class="document-table"
            :header-cell-style="{ 
              background: '#f5f7fa', 
              color: '#606266',
              fontSize: '14px',
              fontWeight: '500'
            }"
            :cell-style="{ fontSize: '13px' }"
          >
            <el-table-column prop="name" label="文档名称" min-width="200" />
            <el-table-column prop="type" label="文档类型" min-width="120" />
            <el-table-column prop="signed_date" label="签署时间" min-width="150" />
          </el-table>
        </div>

        <!-- 经验总结 -->
        <div class="section">
          <h3 class="section-title">经验总结</h3>
          <el-row :gutter="20">
            <el-col :span="12" v-for="experience in reportData.experiences || []" :key="experience.id">
              <el-card class="experience-card" shadow="hover">
                <template #header>
                  <div class="experience-header">
                    <span class="experience-title">{{ experience.title }}</span>
                    <el-tag size="small" type="info">{{ experience.category }}</el-tag>
                  </div>
                </template>
                <div class="experience-content">
                  <p>{{ experience.content }}</p>
                  <div class="experience-time">{{ experience.create_time }}</div>
                </div>
              </el-card>
            </el-col>
          </el-row>
        </div>

        <!-- 变更记录 -->
        <div class="section">
          <h3 class="section-title">变更记录</h3>
          <el-table 
            :data="reportData.changes || []" 
            stripe 
            border 
            class="change-table"
            :header-cell-style="{ 
              background: '#f5f7fa', 
              color: '#606266',
              fontSize: '14px',
              fontWeight: '500'
            }"
            :cell-style="{ fontSize: '13px' }"
          >
            <el-table-column prop="change_type" label="变更类型" min-width="120" />
            <el-table-column prop="description" label="变更描述" min-width="200" />
            <el-table-column prop="impact" label="影响程度" min-width="100">
              <template #default="scope">
                <el-tag :type="getImpactType(scope.row.impact)" size="small">
                  {{ scope.row.impact }}
                </el-tag>
              </template>
            </el-table-column>
            <el-table-column prop="status" label="状态" min-width="100">
              <template #default="scope">
                <el-tag :type="getChangeStatusType(scope.row.status)" size="small">
                  {{ scope.row.status }}
                </el-tag>
              </template>
            </el-table-column>
            <el-table-column prop="create_time" label="创建时间" min-width="150" />
          </el-table>
        </div>

        <!-- 风险与建议 -->
        <div class="section">
          <h3 class="section-title">风险与建议</h3>
          <el-row :gutter="20">
            <el-col :span="12">
              <h4>主要风险</h4>
              <ul class="risk-list">
                <li v-for="risk in reportData.risks || []" :key="risk.id" class="risk-item">
                  <strong>{{ risk.risk_type }}：</strong>{{ risk.description }}
                </li>
              </ul>
            </el-col>
            <el-col :span="12">
              <h4>改进建议</h4>
              <ul class="suggestion-list">
                <li v-for="suggestion in reportData.suggestions || []" :key="suggestion.id" class="suggestion-item">
                  <strong>{{ suggestion.category }}：</strong>{{ suggestion.content }}
                </li>
              </ul>
            </el-col>
          </el-row>
        </div>

       
      </div>

              <!-- 数据统计信息 -->
        <div v-if="reportData" class="data-stats">
          <el-alert
            title="数据加载统计"
            type="info"
            :closable="false"
            show-icon
          >
            <template #default>
              <div class="stats-content">
                <p>人力资源: {{ reportData.resources?.human?.length || 0 }} 人</p>
                <p>干系人: {{ reportData.stakeholders?.length || 0 }} 人</p>
                <p>文档: {{ reportData.documents?.length || 0 }} 个</p>
                <p>经验总结: {{ reportData.experiences?.length || 0 }} 条</p>
                <p>变更记录: {{ reportData.changes?.length || 0 }} 条</p>
                <p>项目进度: {{ reportData.schedule?.length || 0 }} 个阶段</p>
              </div>
            </template>
          </el-alert>
        </div>

        <!-- 进度计算详情 -->
        <div v-if="reportData" class="progress-details">
          <el-card class="details-card" shadow="hover">
            <template #header>
              <div class="details-header">
                <span>进度计算详情</span>
                <el-tag type="info" size="small">调试信息</el-tag>
              </div>
            </template>
            <div class="details-content">
              <el-row :gutter="20">
                <el-col :span="8">
                  <div class="detail-item">
                    <span class="detail-label">总权重：</span>
                    <span class="detail-value">{{ reportData.progress.totalWeight }}</span>
                  </div>
                </el-col>
                <el-col :span="8">
                  <div class="detail-item">
                    <span class="detail-label">已完成权重：</span>
                    <span class="detail-value">{{ reportData.progress.completedWeight }}</span>
                  </div>
                </el-col>
                <el-col :span="8">
                  <div class="detail-item">
                    <span class="detail-label">总贡献度：</span>
                    <span class="detail-value">{{ reportData.progress.completedWeight || 0 }}</span>
                  </div>
                </el-col>
              </el-row>
              <el-row :gutter="20" style="margin-top: 15px;">
                <el-col :span="8">
                  <div class="detail-item">
                    <span class="detail-label">总任务数：</span>
                    <span class="detail-value">{{ reportData.progress.totalTasks }}</span>
                  </div>
                </el-col>
                <el-col :span="8">
                  <div class="detail-item">
                    <span class="detail-label">已完成任务：</span>
                    <span class="detail-value">{{ reportData.progress.completedTasks }}</span>
                  </div>
                </el-col>
                <el-col :span="8">
                  <div class="detail-item">
                    <span class="detail-label">进行中任务：</span>
                    <span class="detail-value">{{ reportData.progress.inProgressTasks }}</span>
                  </div>
                </el-col>
              </el-row>
              <el-divider />
              <div class="calculation-info">
                <h4>计算说明：</h4>
                <ul>
                  <li><strong>权重完成率</strong> = (总贡献度 ÷ 总权重) × 100%</li>
                  <li><strong>任务完成率</strong> = (已完成任务数 ÷ 总任务数) × 100%</li>
                  <li><strong>阶段贡献度</strong> = 阶段权重 × 阶段完成率</li>
                </ul>
              </div>
            </div>
          </el-card>
        </div>

        <!-- 调试信息 -->
        <div v-if="reportData" class="debug-section">
          <el-collapse>
            <el-collapse-item title="调试信息" name="debug">
              <pre>{{ JSON.stringify(reportData, null, 2) }}</pre>
            </el-collapse-item>
          </el-collapse>
        </div>

      <!-- 无数据状态 -->
      <div v-else class="no-data">
        <el-empty description="请配置报表参数并生成报表">
          <el-button type="primary" @click="generateReport">
            生成报表
          </el-button>
        </el-empty>
      </div>
    </el-card>
  </div>
</template>

<script setup>
import { ref, onMounted, computed, watch } from 'vue'
import { ElMessage } from 'element-plus'
import { 
  Document, Refresh, Download, User, DataBoard, Calendar, 
  Refresh as RefreshIcon, Flag, UserFilled, Warning 
} from '@element-plus/icons-vue'
import { getProjectById } from '../../api/project'
import { getUserList } from '../../api/user'
import { getProjectStatusListByProjectId } from '../../api/projectStatus'
import { getProjectIssueListByProjectId } from '../../api/projectIssue'
import { getProjectMilestoneListByProjectId } from '../../api/projectMilestone'
import { getProjectPhaseWeightListByProjectId } from '../../api/projectPhaseWeight'
import { getResourcePlanByProjectId } from '../../api/resourcePlan'
import { getProjectScheduleListByProjectId } from '../../api/projectSchedule'
import { getStakeholderList } from '../../api/stakeholder'
import { api } from '../../utils/apiWrapper'
// 由于可能缺少某些API函数，我们在这里定义它们
// 获取项目文档列表
async function getProjectDocumentsListByProjectId(projectId) {
  try {
    const res = await api.get('/api/data/project_documents', { 
      page: 1, 
      pageSize: 1000, 
      where: { project_id: projectId } 
    })
    console.log('文档管理API返回:', res)
    
    // 处理不同的数据结构
    let records = []
    if (res.records && Array.isArray(res.records)) {
      records = res.records
    } else if (res.data && Array.isArray(res.data)) {
      records = res.data
    } else if (Array.isArray(res)) {
      records = res
    } else {
      console.error('文档管理API返回数据格式不正确:', res)
      return []
    }
    
    // 过滤当前项目的数据
    const data = records.filter(item => item.project_id === projectId)
    console.log('处理后的文档数据:', data)
    return data
  } catch (error) {
    console.error('获取项目文档失败:', error)
    return []
  }
}

// 获取项目经验总结列表
async function getProjectExperienceListByProjectId(projectId) {
  try {
    const res = await api.get('/api/data/project_experience', { 
      page: 1, 
      pageSize: 1000, 
      where: { project_id: projectId } 
    })
    console.log('经验总结API返回:', res)
    
    // 处理不同的数据结构
    let records = []
    if (res.records && Array.isArray(res.records)) {
      records = res.records
    } else if (res.data && Array.isArray(res.data)) {
      records = res.data
    } else if (Array.isArray(res)) {
      records = res
    } else {
      console.error('经验总结API返回数据格式不正确:', res)
      return []
    }
    
    // 过滤当前项目的数据
    const data = records.filter(item => item.project_id === projectId)
    console.log('处理后的经验总结数据:', data)
    return data
  } catch (error) {
    console.error('获取项目经验总结失败:', error)
    return []
  }
}

// 获取项目变更记录列表
async function getProjectChangeListByProjectId(projectId) {
  try {
    const res = await api.get('/api/data/project_change', { 
      page: 1, 
      pageSize: 1000, 
      where: { project_id: projectId } 
    })
    console.log('变更记录API返回:', res)
    
    // 处理不同的数据结构
    let records = []
    if (res.records && Array.isArray(res.records)) {
      records = res.records
    } else if (res.data && Array.isArray(res.data)) {
      records = res.data
    } else if (Array.isArray(res)) {
      records = res
    } else {
      console.error('变更记录API返回数据格式不正确:', res)
      return []
    }
    
    // 过滤当前项目的数据并按变更日期排序
    const data = records.filter(item => item.project_id === projectId).sort((a, b) => {
      return new Date(b.change_date || b.create_time) - new Date(a.change_date || a.create_time)
    })
    
    console.log('处理后的变更数据:', data)
    return data
  } catch (error) {
    console.error('获取项目变更记录失败:', error)
    return []
  }
}

// 定义props
const props = defineProps({
  projectId: {
    type: String,
    default: ''
  },
  projectData: {
    type: Object,
    default: () => ({})
  }
})

const userList = ref([])
const loading = ref(false)
const generating = ref(false)
const exporting = ref(false)
const reportData = ref(null)
const errorMessage = ref('')

const reportConfig = ref({
  startDate: '',
  endDate: '',
  type: 'comprehensive'
})

// 获取状态标签类型
function getStateTagType(state) {
  const stateMap = {
    '计划中': 'info',
    '进行中': 'primary',
    '已完成': 'success',
    '暂停': 'warning'
  }
  return stateMap[state] || 'info'
}

// 根据ID获取用户名
function getUserNameById(id) {
  const user = userList.value.find(u => u.id === id)
  return user ? user.Username : id
}

// 格式化日期
function formatDate(dateString) {
  if (!dateString) return '未知'
  return new Date(dateString).toLocaleString('zh-CN')
}

// 获取严重程度标签类型
function getSeverityType(severity) {
  const severityMap = {
    '低': 'info',
    '中': 'warning',
    '高': 'danger',
    '紧急': 'danger'
  }
  return severityMap[severity] || 'info'
}

// 获取问题状态标签类型
function getIssueStatusType(status) {
  const statusMap = {
    '待处理': 'info',
    '处理中': 'warning',
    '已解决': 'success',
    '已关闭': 'success'
  }
  return statusMap[status] || 'info'
}

// 获取里程碑类型
function getMilestoneType(status) {
  const typeMap = {
    '已完成': 'success',
    '进行中': 'primary',
    '计划中': 'info',
    '延期': 'danger'
  }
  return typeMap[status] || 'info'
}

// 获取里程碑状态标签类型
function getMilestoneStatusType(status) {
  const statusMap = {
    '已完成': 'success',
    '进行中': 'primary',
    '计划中': 'info',
    '延期': 'danger'
  }
  return statusMap[status] || 'info'
}

// 获取优先级标签类型
function getPriorityType(priority) {
  const priorityMap = {
    '低': 'info',
    '中': 'warning',
    '高': 'danger',
    '紧急': 'danger'
  }
  return priorityMap[priority] || 'info'
}

// 获取影响力标签类型
function getInfluenceType(influence) {
  const influenceMap = {
    '高': 'danger',
    '中': 'warning',
    '低': 'info'
  }
  return influenceMap[influence] || 'info'
}

// 获取阶段类型
function getPhaseType(status) {
  const typeMap = {
    '已完成': 'success',
    '进行中': 'primary',
    '计划中': 'info',
    '延期': 'danger'
  }
  return typeMap[status] || 'info'
}

// 获取阶段状态标签类型
function getPhaseStatusType(status) {
  const statusMap = {
    '已完成': 'success',
    '进行中': 'primary',
    '计划中': 'info',
    '延期': 'danger'
  }
  return statusMap[status] || 'info'
}

// 获取影响程度标签类型
function getImpactType(impact) {
  const impactMap = {
    '高': 'danger',
    '中': 'warning',
    '低': 'info'
  }
  return impactMap[impact] || 'info'
}

// 获取变更状态标签类型
function getChangeStatusType(status) {
  const statusMap = {
    '待处理': 'info',
    '处理中': 'warning',
    '已完成': 'success',
    '已关闭': 'success'
  }
  return statusMap[status] || 'info'
}

// 根据完成率获取进度条颜色
function getProgressColor(percentage) {
  // 确保百分比不超过100%
  const normalizedPercentage = Math.min(percentage, 100)
  
  if (normalizedPercentage >= 80) return '#67c23a' // 绿色 - 优秀
  if (normalizedPercentage >= 60) return '#e6a23c' // 橙色 - 良好
  if (normalizedPercentage >= 40) return '#f56c6c' // 红色 - 一般
  return '#909399' // 灰色 - 较差
}

// 加载用户列表
async function loadUsers() {
  try {
    const res = await getUserList()
    userList.value = res.records || []
  } catch (error) {
    console.error('加载用户列表失败:', error)
  }
}

// 生成报表
async function generateReport() {
  if (!reportConfig.value.startDate || !reportConfig.value.endDate) {
    ElMessage.warning('请选择报表周期')
    return
  }
  
  const currentProjectId = props.projectData.project_id || props.projectId
  if (!currentProjectId) {
    ElMessage.warning('请先选择项目')
    return
  }
  
  generating.value = true
  try {
    // 并行获取所有相关数据
    const [
      statusData, 
      issueData, 
      milestoneData, 
      weightData,
      resourceData,
      scheduleData,
      stakeholderData,
      documentData,
      experienceData,
      changeData
    ] = await Promise.all([
      getProjectStatusListByProjectId(currentProjectId),
      getProjectIssueListByProjectId({ page: 1, pageSize: 1000, where: { project_id: currentProjectId } }),
      getProjectMilestoneListByProjectId(currentProjectId),
      getProjectPhaseWeightListByProjectId(currentProjectId),
      getResourcePlanByProjectId(currentProjectId),
      getProjectScheduleListByProjectId(currentProjectId),
      getStakeholderList({ page: 1, pageSize: 1000, where: { project_id: currentProjectId } }),
      getProjectDocumentsListByProjectId(currentProjectId),
      getProjectExperienceListByProjectId(currentProjectId),
      getProjectChangeListByProjectId(currentProjectId)
    ])
    
    // 过滤指定时间范围内的数据
    const startDate = new Date(reportConfig.value.startDate)
    const endDate = new Date(reportConfig.value.endDate)
    
    // 处理项目状态数据
    const filteredStatusData = statusData.filter(item => {
      const itemDate = new Date(item.create_time || item.update_time)
      return itemDate >= startDate && itemDate <= endDate
    })
    
    // 处理问题数据 - 显示所有问题，不按时间过滤
    const issueRecords = issueData.records || issueData || []
    console.log('原始问题数据:', issueRecords)
    const filteredIssueData = Array.isArray(issueRecords) ? 
      issueRecords.filter(item => item.project_id === currentProjectId) : []
    console.log('过滤后的问题数据:', filteredIssueData)
    console.log('问题数据详情:', filteredIssueData.map(item => ({
      id: item.id,
      issue_type: item.issue_type,
      description: item.description,
      severity: item.severity,
      status: item.status,
      create_time: item.create_time
    })))
    
    // 处理里程碑数据
    const filteredMilestoneData = milestoneData.filter(item => {
      const itemDate = new Date(item.expected_date || item.create_time)
      return itemDate >= startDate && itemDate <= endDate
    })
    
    // 处理人力资源数据
    const resourceRecords = resourceData || []
    console.log('原始人力资源数据:', resourceRecords)
    
    // 人力资源数据不需要按时间过滤，直接使用所有数据
    const processedResourceData = Array.isArray(resourceRecords) ? 
      resourceRecords.map(item => {
        // 计算总工时
        let totalHours = 0
        if (item.work_hours) {
          try {
            const monthlyHours = JSON.parse(item.work_hours)
            if (Array.isArray(monthlyHours)) {
              totalHours = monthlyHours.reduce((sum, monthData) => sum + (monthData.hours || 0), 0)
            }
          } catch (e) {
            // 如果解析失败，使用total_hours字段
            totalHours = parseInt(item.total_hours) || 0
          }
        } else {
          totalHours = parseInt(item.total_hours) || 0
        }
        
        return {
          ...item,
          totalHours: totalHours
        }
      }) : []
    
    console.log('处理后的人力资源数据:', processedResourceData)
    
    // 处理项目进度数据
    const scheduleRecords = scheduleData || []
    console.log('原始项目进度数据:', scheduleRecords)
    
    const filteredScheduleData = Array.isArray(scheduleRecords) ? 
      scheduleRecords.filter(item => {
        const itemDate = new Date(item.start_date || item.create_time)
        return itemDate >= startDate && itemDate <= endDate
      }) : []
    
    // 处理干系人数据
    const stakeholderRecords = stakeholderData.records || stakeholderData || []
    console.log('原始干系人数据:', stakeholderRecords)
    const filteredStakeholderData = Array.isArray(stakeholderRecords) ? 
      stakeholderRecords.filter(item => item.project_id === currentProjectId) : []
    console.log('过滤后的干系人数据:', filteredStakeholderData)
    
    // 处理文档数据 - 不需要时间过滤，显示所有文档
    const documentRecords = documentData || []
    console.log('原始文档数据:', documentRecords)
    const filteredDocumentData = Array.isArray(documentRecords) ? 
      documentRecords.filter(item => item.project_id === currentProjectId) : []
    console.log('过滤后的文档数据:', filteredDocumentData)
    
    // 处理经验总结数据 - 不需要时间过滤，显示所有经验总结
    const experienceRecords = experienceData || []
    console.log('原始经验总结数据:', experienceRecords)
    const filteredExperienceData = Array.isArray(experienceRecords) ? 
      experienceRecords.filter(item => item.project_id === currentProjectId) : []
    console.log('过滤后的经验总结数据:', filteredExperienceData)
    
    // 处理变更记录数据 - 不需要时间过滤，显示所有变更记录
    const changeRecords = changeData || []
    console.log('原始变更记录数据:', changeRecords)
    const filteredChangeData = Array.isArray(changeRecords) ? 
      changeRecords.filter(item => item.project_id === currentProjectId) : []
    console.log('过滤后的变更记录数据:', filteredChangeData)
    

    
    // 计算进度数据 - 从项目进度数据中计算
    console.log('开始计算进度数据...')
    
    let totalWeight = 0
    let completedWeight = 0
    let totalTasks = 0
    let completedTasks = 0
    let inProgressTasks = 0
    let totalContribution = 0 // 总贡献度
    
    // 遍历每个阶段，解析progress字段计算完成情况
    scheduleRecords.forEach(item => {
      const weight = parseInt(item.weight) || 0
      totalWeight += weight
      totalTasks++
      
      console.log(`处理阶段: ${item.phase_desc}, 权重: ${weight}, 进度数据:`, item.progress)
      
      if (item.progress) {
        try {
          const progressData = JSON.parse(item.progress)
          console.log(`解析后的进度数据:`, progressData)
          
          // 获取最新的进度数据（最后一个日期）
          const dates = Object.keys(progressData).sort()
          console.log(`进度日期列表:`, dates)
          
          if (dates.length > 0) {
            // 找到最新的非零进度数据
            let latestProgress = null
            let latestDate = null
            
            // 从最新的日期开始往前查找，找到第一个有进度的日期
            for (let i = dates.length - 1; i >= 0; i--) {
              const date = dates[i]
              const progress = progressData[date]
              if (progress && (parseFloat(String(progress.completion_rate)) > 0 || parseFloat(String(progress.completed_weight)) > 0)) {
                latestProgress = progress
                latestDate = date
                break
              }
            }
            
            // 如果没找到有进度的，使用最新的数据
            if (!latestProgress && dates.length > 0) {
              latestDate = dates[dates.length - 1]
              latestProgress = progressData[latestDate]
            }
            
            console.log(`最新日期: ${latestDate}, 最新进度:`, latestProgress)
            
            if (latestProgress) {
              // 确保正确转换字符串为数字
              const completionRate = parseFloat(String(latestProgress.completion_rate)) || 0
              const completedWeightForPhase = parseFloat(String(latestProgress.completed_weight)) || 0
              
              console.log(`阶段完成率: ${completionRate}%, 已完成权重: ${completedWeightForPhase}, 阶段权重: ${weight}`)
              
              // 计算该阶段的实际完成权重（基于完成率）
              const actualCompletedWeight = Math.round((weight * completionRate) / 100)
              completedWeight += actualCompletedWeight
              
              // 计算贡献度（权重 × 完成率）
              const contribution = Math.round((weight * completionRate) / 100)
              totalContribution += contribution
              
              console.log(`阶段实际完成权重: ${actualCompletedWeight}, 贡献度: ${contribution}`)
              
              // 根据完成率判断任务状态
              if (completionRate >= 100) {
                completedTasks++
                console.log(`阶段 ${item.phase_desc} 已完成`)
              } else if (completionRate > 0) {
                inProgressTasks++
                console.log(`阶段 ${item.phase_desc} 进行中`)
              } else {
                console.log(`阶段 ${item.phase_desc} 未开始`)
              }
            }
          }
        } catch (e) {
          console.error('解析进度数据失败:', e, item.progress)
        }
      } else {
        console.log(`阶段 ${item.phase_desc} 无进度数据`)
      }
    })
    
    // 计算权重完成率和任务完成率
    // 权重完成率应该基于总贡献度计算，这样更准确反映项目实际进度
    const weightCompletionRate = totalWeight > 0 ? Math.min(Math.round((totalContribution / totalWeight) * 100), 100) : 0
    const taskCompletionRate = totalTasks > 0 ? Math.round((completedTasks / totalTasks) * 100) : 0
    
    console.log('进度计算详情:', {
      totalWeight,
      completedWeight,
      totalContribution,
      totalTasks,
      completedTasks,
      inProgressTasks,
      weightCompletionRate,
      taskCompletionRate
    })
    
    console.log('进度计算详情:', {
      totalWeight,
      completedWeight,
      totalTasks,
      completedTasks,
      inProgressTasks,
      weightCompletionRate,
      taskCompletionRate
    })
    
    // 计算人力资源和预算
    const totalHours = props.projectData?.total_hours || 0
    const hourlyRate = 100 // 每工时100元
    const totalBudget = totalHours * hourlyRate
    
    // 计算已使用工时和预算
    const usedHours = processedResourceData.reduce((sum, item) => sum + (item.totalHours || 0), 0)
    const usedBudget = usedHours * hourlyRate
    const remainingBudget = totalBudget - usedBudget
    const budgetUsageRate = totalBudget > 0 ? Math.round((usedBudget / totalBudget) * 100) : 0
    
    // 构建人力资源数据
    const humanResources = processedResourceData.map(item => {
      const hours = item.totalHours || 0
      // 计算利用率：基于项目总工时和人员数量
      // 假设每人标准工时为项目总工时的平均值
      const avgHoursPerPerson = totalHours > 0 ? totalHours / Math.max(processedResourceData.length, 1) : 160
      const utilization = avgHoursPerPerson > 0 ? Math.min(Math.round((hours / avgHoursPerPerson) * 100), 100) : 0
      
      return {
        name: item.name || '未知',
        role: item.role || '项目成员',
        hours: hours,
        utilization: utilization
      }
    })
    
    // 添加项目经理
    if (props.projectData?.project_manager) {
      const pmHours = 80
      const avgHoursPerPerson = totalHours > 0 ? totalHours / Math.max(processedResourceData.length, 1) : 160
      const pmUtilization = avgHoursPerPerson > 0 ? Math.min(Math.round((pmHours / avgHoursPerPerson) * 100), 100) : 0
      
      humanResources.unshift({
        name: getUserNameById(props.projectData.project_manager),
        role: '项目经理',
        hours: pmHours,
        utilization: pmUtilization
      })
    }
    
    // 构建报表数据
    reportData.value = {
      progress: {
        totalTasks,
        completedTasks,
        inProgressTasks,
        weightCompletionRate,
        taskCompletionRate,
        totalWeight,
        completedWeight,
        totalHours,
        usedHours,
        remainingHours: totalHours - usedHours
      },
      issues: filteredIssueData.map(item => ({
        id: item.id,
        issue_type: item.issue_type || item.issue_desc || '未分类',
        description: item.description || item.issue_desc || item.issue_content || '无描述',
        severity: item.severity || item.severity_level || '中',
        status: item.status || item.issue_status || '待处理',
        create_time: formatDate(item.create_time || item.createdAt)
      })),
      milestones: filteredMilestoneData.map(item => ({
        id: item.id,
        milestone_name: item.milestone_name || item.milestone_desc || '未命名里程碑',
        description: item.description || item.milestone_desc || '无描述',
        plan_date: formatDate(item.expected_date || item.create_time),
        status: item.status || '计划中'
      })),
      resources: {
        human: humanResources,
        budget: {
          total: totalBudget,
          used: usedBudget,
          remaining: remainingBudget,
          usageRate: budgetUsageRate
        }
      },
      stakeholders: filteredStakeholderData.map(item => ({
        id: item.id,
        name: item.name || item.stakeholder_name || item.stakeholderName || '未知',
        role: item.role || item.stakeholder_role || item.stakeholderRole || '干系人',
        contact: item.contact || item.contact_info || item.contactInfo || '无联系方式',
        influence: item.influence || item.influence_level || item.influenceLevel || '中等'
      })),
      documents: filteredDocumentData.map(item => ({
        id: item.id,
        name: item.content || item.document_name || item.name || '未命名文档',
        type: item.doc_type || item.document_type || item.type || '其他',
        signed_date: formatDate(item.signed_date || item.create_time)
      })),
      experiences: filteredExperienceData.map(item => ({
        id: item.id,
        title: item.aspect || item.experience_title || item.title || item.experienceTitle || '经验总结',
        content: item.summary || item.experience_content || item.content || item.experienceContent || '无内容',
        category: item.discovery_process || item.category || item.experience_category || item.experienceCategory || '其他',
        create_time: formatDate(item.createdAt || item.create_time)
      })),
      changes: filteredChangeData.map(item => ({
        id: item.id,
        change_type: item.initiator || item.change_type || item.type || item.changeType || '变更',
        description: item.change_content || item.change_description || item.description || item.changeDescription || '无描述',
        impact: item.reason || item.impact_level || item.impact || item.impactLevel || '中等',
        status: item.change_date ? '已变更' : item.status || item.change_status || item.changeStatus || '待处理',
        create_time: formatDate(item.createdAt || item.create_time)
      })),
      schedule: scheduleRecords.map(item => {
        // 解析进度数据
        let completionRate = 0
        let completedWeight = 0
        let contribution = 0
        
        if (item.progress) {
          try {
            const progressData = JSON.parse(item.progress)
            const dates = Object.keys(progressData).sort()
            
            if (dates.length > 0) {
              // 找到最新的非零进度数据
              let latestProgress = null
              
              // 从最新的日期开始往前查找，找到第一个有进度的日期
              for (let i = dates.length - 1; i >= 0; i--) {
                const date = dates[i]
                const progress = progressData[date]
                if (progress && (parseFloat(String(progress.completion_rate)) > 0 || parseFloat(String(progress.completed_weight)) > 0)) {
                  latestProgress = progress
                  break
                }
              }
              
              // 如果没找到有进度的，使用最新的数据
              if (!latestProgress && dates.length > 0) {
                const latestDate = dates[dates.length - 1]
                latestProgress = progressData[latestDate]
              }
              
              if (latestProgress) {
                // 确保正确转换字符串为数字
                const rawCompletionRate = parseFloat(String(latestProgress.completion_rate)) || 0
                const phaseWeight = parseInt(item.weight) || 0
                
                // 限制完成率不超过100%
                completionRate = Math.min(rawCompletionRate, 100)
                
                // 计算该阶段的实际完成权重（基于完成率）
                completedWeight = Math.round((phaseWeight * completionRate) / 100)
                
                // 计算贡献度
                contribution = Math.round((phaseWeight * completionRate) / 100)
              }
            }
          } catch (e) {
            console.error('解析进度数据失败:', e)
          }
        }
        
        return {
          id: item.id,
          phase_name: item.phase_desc || item.phase_name || '阶段',
          phase_code: item.phase_code || '',
          weight: parseInt(item.weight) || 0,
          completion_rate: completionRate,
          completed_weight: completedWeight,
          contribution: contribution,
          start_date: formatDate(item.createdAt || item.planned_start || item.start_date),
          end_date: formatDate(item.updatedAt || item.planned_end || item.end_date),
          status: completionRate >= 100 ? '已完成' : completionRate > 0 ? '进行中' : '计划中'
        }
      }),
      risks: filteredIssueData
        .filter(item => item.severity === '高' || item.severity === '紧急')
        .map(item => ({
          id: item.id,
          risk_type: '项目风险',
          description: item.description || item.issue_desc || '高风险问题'
        })),
      suggestions: [
        {
          id: 1,
          category: '流程优化',
          content: weightCompletionRate < 70 ? '建议加强项目管理，提高权重完成率' : '项目进度良好，继续保持'
        },
        {
          id: 2,
          category: '技术改进',
          content: filteredIssueData.length > 5 ? '建议加强技术评审，减少问题数量' : '问题控制良好'
        },
        {
          id: 3,
          category: '资源管理',
          content: budgetUsageRate > 80 ? '预算使用率较高，建议控制成本' : '预算使用合理'
        }
      ],
      nextWeekPlan: filteredMilestoneData
        .filter(item => item.status === '计划中' || item.status === '进行中')
        .slice(0, 5)
        .map(item => ({
          task_name: item.milestone_name || item.milestone_desc || '未命名任务',
          responsible: getUserNameById(props.projectData?.project_manager) || '项目经理',
          priority: item.priority || '中',
          estimated_hours: item.estimated_hours || 40,
          start_date: formatDate(item.expected_date),
          end_date: formatDate(new Date(new Date(item.expected_date).getTime() + 7 * 24 * 60 * 60 * 1000))
        }))
    }
    
    console.log('最终报表数据:', reportData.value)
    ElMessage.success('报表生成成功')
  } catch (error) {
    ElMessage.error('生成报表失败')
    console.error('生成报表失败:', error)
  } finally {
    generating.value = false
  }
}

// 导出Excel
async function exportToExcel() {
  if (!reportData.value) {
    ElMessage.warning('请先生成报表')
    return
  }
  
  exporting.value = true
  try {
    // 创建Excel数据
    const excelData = []
    
    // 添加报表头部信息
    excelData.push(['双周报报表'])
    excelData.push([])
    excelData.push(['项目名称', props.projectData?.project_name || ''])
    excelData.push(['报表周期', `${reportConfig.value.startDate} 至 ${reportConfig.value.endDate}`])
    excelData.push(['生成时间', new Date().toLocaleString('zh-CN')])
    excelData.push([])
    
    // 添加项目基本信息
    excelData.push(['项目基本信息'])
    excelData.push(['项目编号', props.projectData?.project_id || ''])
    excelData.push(['项目名称', props.projectData?.project_name || ''])
    excelData.push(['项目地点', props.projectData?.project_location || ''])
    excelData.push(['项目经理', getUserNameById(props.projectData?.project_manager) || ''])
    excelData.push(['项目状态', props.projectData?.state || ''])
    excelData.push(['总工时', `${reportData.value.progress.totalHours || 0} 小时`])
    excelData.push(['预算总额', `¥${reportData.value.resources?.budget?.total?.toLocaleString() || 0}`])
    excelData.push([])
    
    // 添加数据概览
    excelData.push(['数据概览'])
    excelData.push(['干系人数量', reportData.value.stakeholders?.length || 0])
    excelData.push(['文档数量', reportData.value.documents?.length || 0])
    excelData.push(['经验总结数量', reportData.value.experiences?.length || 0])
    excelData.push(['变更记录数量', reportData.value.changes?.length || 0])
    excelData.push([])
    
    // 添加进度汇总
    excelData.push(['进度汇总'])
    excelData.push(['总任务数', reportData.value.progress.totalTasks])
    excelData.push(['已完成', reportData.value.progress.completedTasks])
    excelData.push(['进行中', reportData.value.progress.inProgressTasks])
    excelData.push(['权重完成率', `${reportData.value.progress.weightCompletionRate}%`])
    excelData.push(['任务完成率', `${reportData.value.progress.taskCompletionRate}%`])
    excelData.push(['总权重', reportData.value.progress.totalWeight])
    excelData.push(['已完成权重', reportData.value.progress.completedWeight])
    excelData.push(['已用工时', `${reportData.value.progress.usedHours || 0} 小时`])
    excelData.push(['剩余工时', `${reportData.value.progress.remainingHours || 0} 小时`])
    excelData.push([])
    
    // 添加问题汇总
    excelData.push(['问题汇总'])
    excelData.push(['问题类型', '问题描述', '严重程度', '状态', '创建时间'])
    reportData.value.issues.forEach(issue => {
      excelData.push([
        issue.issue_type,
        issue.description,
        issue.severity,
        issue.status,
        issue.create_time
      ])
    })
    excelData.push([])
    
    // 添加里程碑进度
    excelData.push(['里程碑进度'])
    excelData.push(['里程碑名称', '描述', '计划日期', '状态'])
    reportData.value.milestones.forEach(milestone => {
      excelData.push([
        milestone.milestone_name,
        milestone.description,
        milestone.plan_date,
        milestone.status
      ])
    })
    excelData.push([])
    
    // 添加资源使用情况
    excelData.push(['资源使用情况'])
    excelData.push(['姓名', '角色', '工时', '利用率'])
    reportData.value.resources.human.forEach(human => {
      excelData.push([
        human.name,
        human.role,
        human.hours,
        `${human.utilization}%`
      ])
    })
    excelData.push([])
    
    // 添加预算信息
    excelData.push(['预算使用情况'])
    excelData.push(['总预算', `¥${reportData.value.resources.budget.total?.toLocaleString()}`])
    excelData.push(['已使用', `¥${reportData.value.resources.budget.used?.toLocaleString()}`])
    excelData.push(['剩余', `¥${reportData.value.resources.budget.remaining?.toLocaleString()}`])
    excelData.push(['使用率', `${reportData.value.resources.budget.usageRate}%`])
    excelData.push([])
    
    // 添加干系人信息
    excelData.push(['干系人管理'])
    excelData.push(['姓名', '角色', '联系方式', '影响力'])
    reportData.value.stakeholders.forEach(stakeholder => {
      excelData.push([
        stakeholder.name,
        stakeholder.role,
        stakeholder.contact,
        stakeholder.influence
      ])
    })
    excelData.push([])
    
    // 添加项目进度信息
    excelData.push(['项目进度'])
    excelData.push(['阶段名称', '阶段代码', '权重', '完成率', '已完成权重', '贡献度', '状态', '开始日期', '结束日期'])
    reportData.value.schedule.forEach(phase => {
      excelData.push([
        phase.phase_name,
        phase.phase_code,
        phase.weight,
        `${phase.completion_rate}%`,
        phase.completed_weight,
        `${phase.contribution}%`,
        phase.status,
        phase.start_date,
        phase.end_date
      ])
    })
    excelData.push([])
    
    // 添加进度趋势分析
    excelData.push(['进度趋势分析'])
    excelData.push(['指标', '数值', '百分比'])
    excelData.push(['权重完成情况', `${reportData.value.progress.completedWeight}/${reportData.value.progress.totalWeight}`, `${reportData.value.progress.weightCompletionRate}%`])
    excelData.push(['任务完成情况', `${reportData.value.progress.completedTasks}/${reportData.value.progress.totalTasks}`, `${reportData.value.progress.taskCompletionRate}%`])
    excelData.push([])
    
    // 添加文档管理信息
    excelData.push(['文档管理'])
    excelData.push(['文档名称', '文档类型', '签署时间'])
    reportData.value.documents.forEach(doc => {
      excelData.push([
        doc.name,
        doc.type,
        doc.signed_date
      ])
    })
    excelData.push([])
    
    // 添加经验总结信息
    excelData.push(['经验总结'])
    excelData.push(['标题', '分类', '内容', '创建时间'])
    reportData.value.experiences.forEach(exp => {
      excelData.push([
        exp.title,
        exp.category,
        exp.content,
        exp.create_time
      ])
    })
    excelData.push([])
    
    // 添加变更记录信息
    excelData.push(['变更记录'])
    excelData.push(['变更类型', '变更描述', '影响程度', '状态', '创建时间'])
    reportData.value.changes.forEach(change => {
      excelData.push([
        change.change_type,
        change.description,
        change.impact,
        change.status,
        change.create_time
      ])
    })
    excelData.push([])
    
    // 添加风险与建议
    excelData.push(['主要风险'])
    reportData.value.risks.forEach(risk => {
      excelData.push([risk.risk_type, risk.description])
    })
    excelData.push([])
    
    excelData.push(['改进建议'])
    reportData.value.suggestions.forEach(suggestion => {
      excelData.push([suggestion.category, suggestion.content])
    })
    excelData.push([])
    
    // // 添加下周计划
    // excelData.push(['下周计划'])
    // excelData.push(['任务名称', '负责人', '优先级', '预计工时', '开始日期', '结束日期'])
    // reportData.value.nextWeekPlan.forEach(plan => {
    //   excelData.push([
    //     plan.task_name,
    //     plan.responsible,
    //     plan.priority,
    //     plan.estimated_hours,
    //     plan.start_date,
    //     plan.end_date
    //   ])
    // })
    
    // 创建CSV格式的数据
    const csvContent = excelData.map(row => 
      row.map(cell => `"${cell || ''}"`).join(',')
    ).join('\n')
    
    // 创建下载链接
    const blob = new Blob(['\ufeff' + csvContent], { type: 'text/csv;charset=utf-8;' })
    const link = document.createElement('a')
    const url = URL.createObjectURL(blob)
    link.setAttribute('href', url)
    link.setAttribute('download', `双周报_${props.projectData?.project_name || '项目'}_${reportConfig.value.startDate}_${reportConfig.value.endDate}.csv`)
    link.style.visibility = 'hidden'
    document.body.appendChild(link)
    link.click()
    document.body.removeChild(link)
    
    ElMessage.success('Excel导出成功')
  } catch (error) {
    ElMessage.error('导出失败')
    console.error('导出失败:', error)
  } finally {
    exporting.value = false
  }
}

// 导出PDF
async function exportToPDF() {
  if (!reportData.value) {
    ElMessage.warning('请先生成报表')
    return
  }
  
  exporting.value = true
  try {
    // 创建PDF内容
    const pdfContent = `
      <html>
        <head>
          <meta charset="utf-8">
          <title>双周报报表</title>
          <style>
            body { font-family: Arial, sans-serif; margin: 20px; }
            .header { text-align: center; margin-bottom: 30px; }
            .title { font-size: 24px; font-weight: bold; margin-bottom: 20px; }
            .info { margin-bottom: 20px; }
            .section { margin-bottom: 30px; }
            .section-title { font-size: 18px; font-weight: bold; margin-bottom: 15px; border-bottom: 1px solid #ccc; padding-bottom: 5px; }
            table { width: 100%; border-collapse: collapse; margin-bottom: 15px; }
            th, td { border: 1px solid #ddd; padding: 8px; text-align: left; }
            th { background-color: #f5f5f5; font-weight: bold; }
            .progress-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 15px; margin-bottom: 20px; }
            .progress-item { text-align: center; padding: 15px; border: 1px solid #ddd; border-radius: 5px; }
            .progress-number { font-size: 24px; font-weight: bold; color: #409eff; }
            .progress-label { font-size: 14px; color: #666; margin-top: 5px; }
          </style>
        </head>
        <body>
          <div class="header">
            <div class="title">双周报报表</div>
            <div class="info">
              <p><strong>项目名称：</strong>${props.projectData?.project_name || ''}</p>
              <p><strong>报表周期：</strong>${reportConfig.value.startDate} 至 ${reportConfig.value.endDate}</p>
              <p><strong>生成时间：</strong>${new Date().toLocaleString('zh-CN')}</p>
            </div>
          </div>
          
          <div class="section">
            <div class="section-title">项目基本信息</div>
            <table>
              <tr><th>项目编号</th><td>${props.projectData?.project_id || ''}</td><th>项目名称</th><td>${props.projectData?.project_name || ''}</td></tr>
              <tr><th>项目地点</th><td>${props.projectData?.project_location || ''}</td><th>项目经理</th><td>${getUserNameById(props.projectData?.project_manager) || ''}</td></tr>
              <tr><th>项目状态</th><td>${props.projectData?.state || ''}</td><th>总工时</th><td>${reportData.value.progress.totalHours || 0} 小时</td></tr>
              <tr><th>预算总额</th><td colspan="3">¥${reportData.value.resources?.budget?.total?.toLocaleString() || 0}</td></tr>
            </table>
          </div>
          
          <div class="section">
            <div class="section-title">数据概览</div>
            <table>
              <tr><th>干系人数量</th><td>${reportData.value.stakeholders?.length || 0}</td><th>文档数量</th><td>${reportData.value.documents?.length || 0}</td></tr>
              <tr><th>经验总结数量</th><td>${reportData.value.experiences?.length || 0}</td><th>变更记录数量</th><td>${reportData.value.changes?.length || 0}</td></tr>
            </table>
          </div>
          
          <div class="section">
            <div class="section-title">进度汇总</div>
            <div class="progress-grid">
              <div class="progress-item">
                <div class="progress-number">${reportData.value.progress.totalTasks}</div>
                <div class="progress-label">总任务数</div>
              </div>
              <div class="progress-item">
                <div class="progress-number">${reportData.value.progress.completedTasks}</div>
                <div class="progress-label">已完成</div>
              </div>
              <div class="progress-item">
                <div class="progress-number">${reportData.value.progress.inProgressTasks}</div>
                <div class="progress-label">进行中</div>
              </div>
              <div class="progress-item">
                <div class="progress-number">${reportData.value.progress.weightCompletionRate}%</div>
                <div class="progress-label">权重完成率</div>
              </div>
              <div class="progress-item">
                <div class="progress-number">${reportData.value.progress.taskCompletionRate}%</div>
                <div class="progress-label">任务完成率</div>
              </div>
              <div class="progress-item">
                <div class="progress-number">${reportData.value.progress.totalWeight}</div>
                <div class="progress-label">总权重</div>
              </div>
              <div class="progress-item">
                <div class="progress-number">${reportData.value.progress.completedWeight}</div>
                <div class="progress-label">已完成权重</div>
              </div>
              <div class="progress-item">
                <div class="progress-number">${reportData.value.progress.usedHours || 0}</div>
                <div class="progress-label">已用工时</div>
              </div>
              <div class="progress-item">
                <div class="progress-number">${reportData.value.progress.remainingHours || 0}</div>
                <div class="progress-label">剩余工时</div>
              </div>
            </div>
          </div>
          
          <div class="section">
            <div class="section-title">问题汇总</div>
            <table>
              <thead>
                <tr><th>问题类型</th><th>问题描述</th><th>严重程度</th><th>状态</th><th>创建时间</th></tr>
              </thead>
              <tbody>
                ${reportData.value.issues.map(issue => `
                  <tr>
                    <td>${issue.issue_type}</td>
                    <td>${issue.description}</td>
                    <td>${issue.severity}</td>
                    <td>${issue.status}</td>
                    <td>${issue.create_time}</td>
                  </tr>
                `).join('')}
              </tbody>
            </table>
          </div>
          
          <div class="section">
            <div class="section-title">里程碑进度</div>
            <table>
              <thead>
                <tr><th>里程碑名称</th><th>描述</th><th>计划日期</th><th>状态</th></tr>
              </thead>
              <tbody>
                ${reportData.value.milestones.map(milestone => `
                  <tr>
                    <td>${milestone.milestone_name}</td>
                    <td>${milestone.description}</td>
                    <td>${milestone.plan_date}</td>
                    <td>${milestone.status}</td>
                  </tr>
                `).join('')}
              </tbody>
            </table>
          </div>
          
          <div class="section">
            <div class="section-title">资源使用情况</div>
            <table>
              <thead>
                <tr><th>姓名</th><th>角色</th><th>工时</th><th>利用率</th></tr>
              </thead>
              <tbody>
                ${reportData.value.resources.human.map(human => `
                  <tr>
                    <td>${human.name}</td>
                    <td>${human.role}</td>
                    <td>${human.hours}</td>
                    <td>${human.utilization}%</td>
                  </tr>
                `).join('')}
              </tbody>
            </table>
          </div>
          
          <div class="section">
            <div class="section-title">预算使用情况</div>
            <table>
              <tr><th>总预算</th><td>¥${reportData.value.resources.budget.total?.toLocaleString()}</td></tr>
              <tr><th>已使用</th><td>¥${reportData.value.resources.budget.used?.toLocaleString()}</td></tr>
              <tr><th>剩余</th><td>¥${reportData.value.resources.budget.remaining?.toLocaleString()}</td></tr>
              <tr><th>使用率</th><td>${reportData.value.resources.budget.usageRate}%</td></tr>
            </table>
          </div>
          
          <div class="section">
            <div class="section-title">干系人管理</div>
            <table>
              <thead>
                <tr><th>姓名</th><th>角色</th><th>联系方式</th><th>影响力</th></tr>
              </thead>
              <tbody>
                ${reportData.value.stakeholders.map(stakeholder => `
                  <tr>
                    <td>${stakeholder.name}</td>
                    <td>${stakeholder.role}</td>
                    <td>${stakeholder.contact}</td>
                    <td>${stakeholder.influence}</td>
                  </tr>
                `).join('')}
              </tbody>
            </table>
          </div>
          
          <div class="section">
            <div class="section-title">项目进度</div>
            <table>
              <thead>
                <tr><th>阶段名称</th><th>阶段代码</th><th>权重</th><th>完成率</th><th>已完成权重</th><th>贡献度</th><th>状态</th><th>开始日期</th><th>结束日期</th></tr>
              </thead>
              <tbody>
                ${reportData.value.schedule.map(phase => `
                  <tr>
                    <td>${phase.phase_name}</td>
                    <td>${phase.phase_code}</td>
                    <td>${phase.weight}</td>
                    <td>${phase.completion_rate}%</td>
                    <td>${phase.completed_weight}</td>
                    <td>${phase.contribution}%</td>
                    <td>${phase.status}</td>
                    <td>${phase.start_date}</td>
                    <td>${phase.end_date}</td>
                  </tr>
                `).join('')}
              </tbody>
            </table>
          </div>
          
                    <div class="section">
            <div class="section-title">进度趋势分析</div>
            <table>
              <thead>
                <tr><th>指标</th><th>数值</th><th>百分比</th></tr>
              </thead>
              <tbody>
                <tr>
                  <td>权重完成情况</td>
                  <td>${reportData.value.progress.completedWeight}/${reportData.value.progress.totalWeight}</td>
                  <td>${reportData.value.progress.weightCompletionRate}%</td>
                </tr>
                <tr>
                  <td>任务完成情况</td>
                  <td>${reportData.value.progress.completedTasks}/${reportData.value.progress.totalTasks}</td>
                  <td>${reportData.value.progress.taskCompletionRate}%</td>
                </tr>
                <tr>
                  <td>总贡献度</td>
                  <td>${reportData.value.progress.completedWeight || 0}</td>
                  <td>-</td>
                </tr>
              </tbody>
            </table>
          </div>
          
          <div class="section">
            <div class="section-title">文档管理</div>
            <table>
              <thead>
                <tr><th>文档名称</th><th>文档类型</th><th>签署时间</th></tr>
              </thead>
              <tbody>
                ${reportData.value.documents.map(doc => `
                  <tr>
                    <td>${doc.name}</td>
                    <td>${doc.type}</td>
                    <td>${doc.signed_date}</td>
                  </tr>
                `).join('')}
              </tbody>
            </table>
          </div>
          
          <div class="section">
            <div class="section-title">经验总结</div>
            ${reportData.value.experiences.map(exp => `
              <div style="margin-bottom: 15px; padding: 10px; border: 1px solid #ddd; border-radius: 5px;">
                <h4 style="margin: 0 0 10px 0; color: #409eff;">${exp.title}</h4>
                <p style="margin: 0 0 5px 0; color: #666;">分类: ${exp.category}</p>
                <p style="margin: 0 0 5px 0;">${exp.content}</p>
                <p style="margin: 0; font-size: 12px; color: #999;">${exp.create_time}</p>
              </div>
            `).join('')}
          </div>
          
          <div class="section">
            <div class="section-title">变更记录</div>
            <table>
              <thead>
                <tr><th>变更类型</th><th>变更描述</th><th>影响程度</th><th>状态</th><th>创建时间</th></tr>
              </thead>
              <tbody>
                ${reportData.value.changes.map(change => `
                  <tr>
                    <td>${change.change_type}</td>
                    <td>${change.description}</td>
                    <td>${change.impact}</td>
                    <td>${change.status}</td>
                    <td>${change.create_time}</td>
                  </tr>
                `).join('')}
              </tbody>
            </table>
          </div>
          
          <div class="section">
            <div class="section-title">风险与建议</div>
            <h4>主要风险</h4>
            <ul>
              ${reportData.value.risks.map(risk => `<li><strong>${risk.risk_type}：</strong>${risk.description}</li>`).join('')}
            </ul>
            <h4>改进建议</h4>
            <ul>
              ${reportData.value.suggestions.map(suggestion => `<li><strong>${suggestion.category}：</strong>${suggestion.content}</li>`).join('')}
            </ul>
          </div>
          
        </body>
      </html>
    `
    
    // 创建新窗口显示PDF内容
    const newWindow = window.open('', '_blank')
    newWindow.document.write(pdfContent)
    newWindow.document.close()
    
    // 等待内容加载完成后打印
    setTimeout(() => {
      newWindow.print()
    }, 1000)
    
    ElMessage.success('PDF导出成功')
  } catch (error) {
    ElMessage.error('导出失败')
    console.error('导出失败:', error)
  } finally {
    exporting.value = false
  }
}

// 监听项目数据变化
watch(() => props.projectData, (newProjectData) => {
  if (newProjectData && newProjectData.project_id) {
    // 设置默认的报表周期（最近两周）
    const endDate = new Date()
    const startDate = new Date()
    startDate.setDate(endDate.getDate() - 14)
    
    reportConfig.value.startDate = startDate.toISOString().split('T')[0]
    reportConfig.value.endDate = endDate.toISOString().split('T')[0]
  }
}, { deep: true })

onMounted(() => {
  loadUsers()
})
</script>

<style scoped>
.biweekly-report-container {
  padding: 20px;
  background: #f5f7fa;
  min-height: calc(100vh - 120px);
}

.report-card {
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 24px;
  padding-bottom: 20px;
  border-bottom: 1px solid #ebeef5;
}

.title-section {
  flex: 1;
}

.page-title {
  margin: 0 0 8px 0;
  font-size: 24px;
  font-weight: 600;
  color: #303133;
  display: flex;
  align-items: center;
  gap: 8px;
}

.title-icon {
  font-size: 24px;
  color: #67c23a;
}

.description {
  margin: 0;
  font-size: 14px;
  color: #909399;
  line-height: 1.5;
}

.action-buttons {
  display: flex;
  gap: 12px;
}

.config-section {
  margin-bottom: 24px;
  padding: 20px;
  background: #f8f9fa;
  border-radius: 8px;
}

.loading-section {
  padding: 40px 0;
}

.report-content {
  padding: 20px 0;
}

.report-header {
  text-align: center;
  margin-bottom: 30px;
  padding-bottom: 20px;
  border-bottom: 2px solid #ebeef5;
}

.report-title {
  font-size: 28px;
  font-weight: 700;
  color: #303133;
  margin: 0 0 20px 0;
}

.report-info {
  display: flex;
  justify-content: space-around;
  flex-wrap: wrap;
  gap: 20px;
}

.report-info p {
  margin: 0;
  font-size: 14px;
  color: #606266;
}

.section {
  margin-bottom: 30px;
}

.section-title {
  font-size: 18px;
  font-weight: 600;
  color: #303133;
  margin: 0 0 20px 0;
  padding-bottom: 10px;
  border-bottom: 1px solid #ebeef5;
}

.progress-card {
  text-align: center;
  padding: 20px;
}

.progress-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.progress-number {
  font-size: 32px;
  font-weight: 700;
  color: #409eff;
}

.progress-label {
  font-size: 14px;
  color: #606266;
}

.overview-card {
  text-align: center;
  padding: 20px;
  border-radius: 12px;
  transition: all 0.3s ease;
}

.overview-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.1);
}

.overview-item {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
}

.overview-icon {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 24px;
}

.overview-content {
  text-align: left;
}

.overview-number {
  font-size: 28px;
  font-weight: 700;
  color: #303133;
  line-height: 1;
}

.overview-label {
  font-size: 14px;
  color: #909399;
  margin-top: 4px;
}

.budget-info {
  padding: 20px;
  background: #f8f9fa;
  border-radius: 8px;
}

.budget-item {
  display: flex;
  justify-content: space-between;
  margin-bottom: 10px;
  padding: 8px 0;
  border-bottom: 1px solid #ebeef5;
}

.budget-item:last-child {
  border-bottom: none;
  margin-bottom: 0;
}

.budget-label {
  font-weight: 600;
  color: #606266;
}

.budget-value {
  font-weight: 700;
  color: #409eff;
}

.risk-list,
.suggestion-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.risk-item,
.suggestion-item {
  padding: 10px 0;
  border-bottom: 1px solid #ebeef5;
  line-height: 1.6;
}

.risk-item:last-child,
.suggestion-item:last-child {
  border-bottom: none;
}

.experience-card {
  margin-bottom: 16px;
  border-radius: 8px;
  transition: all 0.3s ease;
}

.experience-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.1);
}

.experience-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.experience-title {
  font-weight: 600;
  color: #303133;
  font-size: 16px;
}

.experience-content {
  padding: 8px 0;
}

.experience-content p {
  margin: 0 0 8px 0;
  line-height: 1.6;
  color: #606266;
}

.experience-time {
  font-size: 12px;
  color: #909399;
  text-align: right;
}

.trend-card {
  border-radius: 8px;
  transition: all 0.3s ease;
}

.trend-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.1);
}

.trend-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.trend-content {
  padding: 20px 0;
}

.trend-description {
  margin: 10px 0 0 0;
  font-size: 14px;
  color: #606266;
  text-align: center;
}

.data-stats {
  margin-bottom: 20px;
}

.progress-details {
  margin-bottom: 20px;
}

.details-card {
  border-radius: 8px;
}

.details-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.details-content {
  padding: 10px 0;
}

.detail-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid #f0f0f0;
}

.detail-item:last-child {
  border-bottom: none;
}

.detail-label {
  font-weight: 600;
  color: #606266;
}

.detail-value {
  font-weight: 700;
  color: #409eff;
  font-size: 16px;
}

.calculation-info {
  margin-top: 20px;
  padding: 15px;
  background: #f8f9fa;
  border-radius: 6px;
}

.calculation-info h4 {
  margin: 0 0 10px 0;
  color: #303133;
  font-size: 14px;
}

.calculation-info ul {
  margin: 0;
  padding-left: 20px;
}

.calculation-info li {
  margin-bottom: 5px;
  line-height: 1.6;
  color: #606266;
}

.stats-content {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  margin-top: 10px;
}

.stats-content p {
  margin: 0;
  padding: 8px;
  background: #f0f9ff;
  border-radius: 4px;
  text-align: center;
  font-weight: 500;
}

.no-data {
  padding: 60px 0;
  text-align: center;
}

/* 统一表格样式 */
.stakeholder-table,
.progress-table,
.issue-table,
.resource-table,
.document-table,
.change-table,
.plan-table {
  margin-bottom: 20px;
  border-radius: 8px;
  overflow: hidden;
}

:deep(.el-table) {
  border-radius: 8px;
}

:deep(.el-table th) {
  background: #f5f7fa !important;
  font-weight: 600;
}

:deep(.el-table td) {
  padding: 8px 0;
}

:deep(.el-descriptions) {
  border-radius: 8px;
  overflow: hidden;
}

:deep(.el-descriptions__label) {
  font-weight: 600;
  background: #f5f7fa;
}

:deep(.el-button) {
  border-radius: 8px;
  font-weight: 500;
}

:deep(.el-timeline-item__node) {
  background-color: #409eff;
}

:deep(.el-timeline-item__wrapper) {
  padding-left: 20px;
}

@media (max-width: 768px) {
  .biweekly-report-container {
    padding: 10px;
  }
  
  .header {
    flex-direction: column;
    gap: 16px;
    align-items: stretch;
  }
  
  .action-buttons {
    justify-content: flex-end;
  }
  
  .report-info {
    flex-direction: column;
    align-items: center;
  }
  
  .config-section {
    padding: 15px;
  }
  
  .report-title {
    font-size: 24px;
  }
  
  .progress-number {
    font-size: 24px;
  }
  
  .experience-card {
    margin-bottom: 12px;
  }
  
  .experience-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }
  
  .experience-title {
    font-size: 14px;
  }
  
  .experience-content {
    padding: 4px 0;
  }
  
  .experience-content p {
    font-size: 13px;
  }
  
  .experience-time {
    font-size: 11px;
  }
}
</style> 